#ifndef SP_DRIVER_FLOPPY_H
#define SP_DRIVER_FLOPPY_H

#define FLOPPY_REG_A       					0x3F0 // read-only
#define FLOPPY_REG_B        				0x3F1 // read-only
#define FLOPPY_REG_DIGITAL_OUTPUT  			0x3F2
#define FLOPPY_REG_TAPE_DRIVE     			0x3F3
#define FLOPPY_REG_MAIN_STATUS				0x3F4 // read-only
#define FLOPPY_REG_DATA_RATE_SELECT			0x3F4 // write-only
#define FLOPPY_REG_DATA_FIFO                0x3F5
#define FLOPPY_REG_DIGITAL_INPUT			0x3F7 // read-only
#define FLOPPY_REG_CONFIGURATION_CONTROL	0x3F7 //write only

#define FLOPPY_CMD_READ_TRACK				2
#define FLOPPY_CMD_SPECIFY					3
#define FLOPPY_CMD_SENSE_DRIVE_STATUS		4
#define FLOPPY_CMD_WRITE_DATA				5
#define FLOPPY_CMD_READ_DATA				6
#define FLOPPY_CMD_RECALIBRATE				7
#define FLOPPY_CMD_SENSE_INTERRUPT			8
#define FLOPPY_CMD_WRITE_DELETED_DATA		9
#define FLOPPY_CMD_READ_ID					10
#define FLOPPY_CMD_READ_DELETED_DATA		12
#define FLOPPY_CMD_FORMAT_TRACK				13
#define FLOPPY_CMD_SEEK						15
#define FLOPPY_CMD_VERSION					16
#define FLOPPY_CMD_SCAN_EQUAL				17
#define FLOPPY_CMD_PERPENDICULAR_MODE		18
#define FLOPPY_CMD_CONFIGURE				19
#define FLOPPY_CMD_VERIFY					22
#define FLOPPY_CMD_SCAN_LOW_OR_EQUAL		25
#define FLOPPY_CMD_SCAN_HIGH_OR_EQUAL		29

//static const int floppy_base = 0x03f0;
//FLOPPY_DOR  = 2,  // digital output register
//FLOPPY_MSR  = 4,  // master status register, read only
//FLOPPY_FIFO = 5,  // data FIFO, in DMA operation for commands
//FLOPPY_CCR  = 7
   
#include <system/regs.h>
#include <system/mod.h>


extern module_t floppy_module;

uint32_t floppy_init();
int32_t floppy_reset();
static void floppy_callback(regs_t *);
uint32_t floppy_shut();

uint8_t floppy_read_data();
void floppy_write_cmd(uint8_t);
void floppy_check_interrupt(int32_t *, int32_t *);
uint8_t floppy_int;
int32_t floppy_calibrate();
int32_t floppy_seek(unsigned, int);
void floppy_motor(int);

#endif
